package org.jiucai.app.admin.auth.util;

import javax.servlet.http.HttpSession;

import org.jiucai.app.admin.data.AdminConstant;
import org.jiucai.appframework.base.util.AppHolder;
import org.jiucai.cas.domain.UserInfo;

/**
 * 从 session 和 request 获取数据的静态工具类
 * 
 * @author zhaidw
 * 
 */
public class AdminUserUtil {

	public static final Long getUserId() {
		Long userId = null;

		UserInfo user = getUser();

		if (null != user) {
			userId = user.getUserId();
		}

		return userId;
	}

	/**
	 * 获取当前登录用户信息对象
	 * 
	 * @param request
	 * @return
	 */
	public static UserInfo getUser() {
		UserInfo user = null;

		HttpSession session = AppHolder.getSession();

		if (null != session) {
			// 通过认证后，设置会话用户ID
			Object sessUid = session.getAttribute(AdminConstant.AUTH_SESS_USER);

			if (null != sessUid) {
				user = (UserInfo) sessUid;
			}
		}

		return user;

	}

}
